package ilarele.planner.Adapters;

import ilarele.planner.Activities.R;
import ilarele.planner.Project.Project;

import java.util.List;

import android.content.Context;
import android.content.res.TypedArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;

public class GridViewCellAdapter extends ArrayAdapter<Cell>
{
	private LayoutInflater m_inflater;
	private Project project;
	private int layout_item_id;
	private int min = 0;
	private int itemBack;
	
	
	public GridViewCellAdapter(Context context, int layout_item_id,
			List<Cell> items_list, Project prj)
	{
		super(context, layout_item_id, items_list);
		this.layout_item_id = layout_item_id;
		this.project = prj;
		m_inflater = LayoutInflater.from(context);
		TypedArray a = context.obtainStyledAttributes(R.styleable.Gallery1);
		itemBack = a.getResourceId(
				R.styleable.Gallery1_android_galleryItemBackground, 0);
		a.recycle();
	}

	@Override
	public boolean hasStableIds()
	{
		return true;
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		Cell crt_cell = getItem(position);
		if (convertView == null)
		{
			convertView = m_inflater.inflate(layout_item_id, parent, false);
		}
		ImageButton task_pic = (ImageButton) convertView.findViewById(R.id.task_pic);
		
		if (crt_cell == null)
		{
			task_pic.setVisibility(View.INVISIBLE);
		}
		else
		{
			// GUI
//			TextView task_name = (TextView) convertView.findViewById(R.id.task_name);
//			task_name.setText(crt_task.getName());
			task_pic.setVisibility(View.VISIBLE);
				
		}
		convertView.setBackgroundResource(R.drawable.back);
	
		return convertView;
	}
	private int getDP(int pix)
	{
		return (int) (getContext().getResources().getDisplayMetrics().density * pix);
	}
}
